#ifndef __EEPROM_H
#define __EEPROM_H

#include "hc32f460.h"
#include "dev_i2c.h"
#include "CommFunc_API.h"
#include "anv_leaks.h"

#define  EEPROM_SDA GET_PIN(E, 7)
#define  EEPROM_SCL GET_PIN(E, 8)  
#define CS_SPI_256401               10
#define CS_SPI_256402               11

#define SINGLE_CHIP_SIZE		((uint32_t)(64*1024))//eeprom大小
#define PAGE_SIZE		128
#define MEM_24LC25601_DEVADDR       0xA0             //EEPROM 的地址

typedef enum {
    EEPROM_OP_ERASE,
    EEPROM_OP_WRITE,
    EEPROM_OP_READ,
    EEPROM_OP_VERIFY
} eeprom_op_t;
// eeprom 操作请求结构
typedef struct {
    eeprom_op_t op_type;
    rt_uint32_t addr;
    rt_uint32_t size;
    void *data;
    rt_sem_t completion_sem;
    rt_err_t result;
} eeprom_req_t;
extern uint8_t g_byEEErrTimes[2];	//EEPROM存储器故障次数
extern struct rt_i2c_bus_device *i2c_ee_dev;

void EEPROM_thread_entry(void *parameter);
uint16_t ReadXX24XXX(uint8_t ChipNo, uint16_t Addr, uint16_t Len, uint8_t * pBuf);
uint16_t WriteXX24XXX(uint8_t ChipNo, uint16_t Addr, uint16_t Len, uint8_t * pBuf);
rt_err_t eeprom_Read_sync(rt_uint32_t addr, const void *data, rt_uint32_t size);
rt_err_t eeprom_write_sync(rt_uint32_t addr, const void *data, rt_uint32_t size);
#endif